package com.hst.capacity.infra.convertor;

import com.hst.capacity.domain.model.entity.auth.TokenEntity;
import com.hst.capacity.domain.model.entity.auth.UserEntity;
import com.hst.capacity.domain.model.entity.franchisee.FranchiseeEntity;
import com.hst.capacity.domain.model.entity.franchisee.FranchiseeUserEntity;
import com.hst.capacity.domain.model.entity.setting.station.SysRegionEntity;
import com.hst.capacity.domain.model.response.auth.TokenVO;
import com.hst.capacity.domain.model.response.auth.UserBindingVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;

/**
 *  访问控制（身份验证、授权等）的POJO属性转换器
 *
 * @author Hans
 * */
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface AuthConvertor {

    AuthConvertor INSTANCE = Mappers.getMapper(AuthConvertor.class);

    /**
     *  实体转VO
     *
     * @param tokenEntity
     * @return TokenVO
     * */
    @Mapping(target = "token", source = "accessToken")
    TokenVO convert(TokenEntity tokenEntity);

    /**
     *  实体转用户绑定信息VO
     *
     * @return UserBindingVO
     * */
    @Mapping(target = "user.id", source = "franchiseeUser.user.id")
    @Mapping(target = "user.userType", source = "franchiseeUser.userType")
    @Mapping(target = "user.displayName", source = "franchiseeUser.displayName")
    @Mapping(target = "merchant.merchantId", source = "franchisee.idFranchisee")
    @Mapping(target = "merchant.merchant", source = "franchisee.fullName")
    @Mapping(target = "merchant.cityCode", source = "franchisee.regionCode")
    @Mapping(target = "merchant.cityName", source = "sysRegionEntity.name")
    UserBindingVO convert(FranchiseeUserEntity franchiseeUser, FranchiseeEntity franchisee, SysRegionEntity sysRegionEntity);

}
